/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-09-05 09:45:28
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-10-11 12:02:32
 * @FilePath: /react18-vite-admin/src/api/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { service } from '@/service/app/useRequest';
import { UserListItem, UserDetail } from '@/typings/api/user';

export class UserListParam implements PageParam<keyof UserListItem> {
    current = 1;
    size = 10;
    valid?: boolean;
    roleId?: number;
    departmentId?: number;
    username?: string;
}

export const readUserList = (data: UserListParam) => {
    return service<HttpResult<PageResult<UserListItem>>>({
        url: '/admin/api/user/search',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const readUserDetail = (id: number) => {
    return service<HttpResult<UserDetail>>({
        url: `/admin/api/user/get/${id}`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class UserParam {
    id?: number;
    username = '';
    valid = true;
    roleIdList: number[] = [];
    departmentIdList: number[] = [];
}

export const createOrUpdateUser = (data: UserParam) => {
    return service<HttpResult>({
        url: '/admin/api/user/save',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};
